package com.software.loginregister.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.software.loginregister.R;

import java.util.Calendar;

public class PublishActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish);
        // 设置日期显示
        setupDateTime();
        // 设置状态栏
        setStatusBar();

        // 发布作品点击事件
        findViewById(R.id.cv_publish_work).setOnClickListener(v -> {
            Intent intent = new Intent(this, PublishWorkActivity.class);
            startActivity(intent);
        });

        // 发布帖子点击事件
        findViewById(R.id.cv_publish_post).setOnClickListener(v -> {
            Intent intent = new Intent(this, PublishPostActivity.class);
            startActivity(intent);
        });

        // 草稿箱点击事件
        findViewById(R.id.tv_publish_drafts).setOnClickListener(v -> {
            Intent intent = new Intent(this, DraftsActivity.class);
            startActivity(intent);
        });
        // 关闭按钮点击事件
        findViewById(R.id.iv_close).setOnClickListener(v -> finish());
    }

    private void setupDateTime() {
        Calendar calendar = Calendar.getInstance();
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

        TextView tvDate = findViewById(R.id.tv_publish_date);
        TextView tvMonth = findViewById(R.id.tv_publish_month);
        TextView tvDay = findViewById(R.id.tv_publish_day);

        tvDate.setText(weekDays[calendar.get(Calendar.DAY_OF_WEEK) - 1]);
        tvMonth.setText(String.format("%d/%d", calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR)));
        tvDay.setText(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
    }

    private void setStatusBar() {
        Window window = getWindow();
        // 设置状态栏背景为透明
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);

        // 设置状态栏文字颜色为深色
        View decorView = window.getDecorView();
        int flags = decorView.getSystemUiVisibility();
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        decorView.setSystemUiVisibility(flags);

    }
}